import java.util.Scanner;
import java.io.*;

/**
 * @author Team 29
 * This class documents a users treatment records within the database.
 *
 */
public class TreatmentRecord {

	public String fileName;
	public TreatmentRecord(String fileName){
		this.fileName=fileName;
	}
	public String getTreatmentRecord(){
		String s = "";
		try{
			Scanner read = new Scanner(new File("src/"+fileName));
			while (read.hasNextLine()){
				s+=read.nextLine()+"\n";
			}
		}
		catch(Exception e){
			System.out.println("Unable to open Treatment Record: "+fileName);
			Logger.log("Unable to open Treatment Record: "+fileName);
		}
		return s;
	}
	
	public void setTreatmentRecord(String history){
		try{
			FileWriter write = new FileWriter(new File("src/"+fileName), true);
			write.append(history);
			write.close();
		}
		catch(Exception e){
			System.out.println("Unable to write to Treatment Record: "+fileName);
			Logger.log("Unable to write to Treatment Record: "+fileName);
		}
	}
	
	public String toString(){
		return fileName;
	}
	
	public static TreatmentRecord fromString(String fileName){
		return new TreatmentRecord(fileName);
	}
}
